package com.ztk.threadbasic.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;

public class CompletableFuture03 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            try {
                System.out.println("开始执行有返回结果的supplyAsync方法");
                Thread.sleep(2000);
                System.out.println("开始计算");
                int count = 1;
                for (int i = 0; i < 10; i++) {
                    count *= (count + i);
                }
                return count;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return null;
        }).thenApply(number -> {
            for (int i = 0; i < 5; i++) {
                number = number / 5;
            }
            return number;
        });

        System.out.println(future.join());
    }
}
